<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>4841：[Neerc2016]Cactus Construction</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Neerc2016]Cactus Construction</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">[Neerc2016]Cactus Construction</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                [Neerc2016]Cactus Construction                </h1>
                <p>时间限制：100s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div>首先定义一种建图的方式，先选出一个常数C表示颜色的种类数，然后要建出一个含n个点的仙人掌，一开始图中一</div>
<div>共n连通块，n个点，没有边，每个点初始颜色均为1，你有如下3种操作可以使用：</div>
<div>1、join a b：将a所在的连通块和b所在的连通块划分为同一个连通块，不在a和b之间连边，必须保证a和b不能在同一个连通块。</div>
<div>2、recolor a c1 c2：将a所在的连通块中所有颜色为c1的点的颜色都改成c2。</div>
<div>3、connect a c1 c2：将a所在的连通块中颜色为c1的点和颜色为c2的点之间互相连边，如果c1=c2，则重边不连，</div>
<div>如果两个要连边的点已经连了一条边，则该次操作仍会在这两个点之间连边（当然重边是不允许出现在仙人掌中的</div>
<div>，所以你必须设法避免这种情况）。</div>
<div>给出最后构成的仙人掌，请你在保证C最小（保证C最大不会超过4）的情况下，输出构造方案。</div>
<div></div>
<p></p></p><hr/><h3>输入格式</h3><p><div>第一行两个数n（n&lt;=50000,m&lt;=50000)，表示最后构成的仙人掌有n个点，m条路径。</div>
<div>接下来m行，每行第一个数x(x&lt;=1000),紧接着x个数，表示一条路径。</div>
<div></div>
<p></p></p><hr/><h3>输出格式</h3><p><div>第一行输出一个数q，表示操作次数。</div>
<div>接下来q行每行第一个输出一个字母：j或r或c，分别表示以上三种操作的第1、2、3种</div>
<div>若第一个字母为j，则接下来两个数a,b，含义如上所示</div>
<div>若第一个字母为r或c，则接下来三个数a,c1,c2，含义如上所述。</div>
<div></div>
<p></p></p><hr/><h3>样例输入</h3><pre>8 2
5 1 2 3 4 7
5 4 5 6 1 8</pre><hr/><h3>样例输出</h3><pre>17
r 2 1 2
j 2 3
c 2 1 2
r 6 1 2
j 5 6
c 6 1 2
r 4 1 3
j 4 3
j 4 6
j 4 7
c 4 3 1
r 4 3 1
r 8 1 2
r 1 1 3
j 1 8
j 1 4
c 1 3 2</pre><hr/><h3>提示</h3><p><p>&nbsp;请不要提交！</p></p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=4841" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=4841" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>